﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;

namespace MyTestProject {

    public class TestCompositingMode {
        [Fact]
        public void TestConstructor () {
            var cmode = new CompositingMode ();

            Assert.Equal (null, cmode.Blender);
            Assert.Equal (CompositingMode.Replace, cmode.Blending);
            Assert.Equal (0.0f, cmode.AlphaThreshold);
            Assert.Equal (CompositingMode.GEqual, cmode.AlphaTest);
            Assert.Equal (0.0f, cmode.DepthOffsetFactor);
            Assert.Equal (0.0f, cmode.DepthOffsetUnits);
            Assert.Equal (true, cmode.DepthTestEnabled);
            Assert.Equal (CompositingMode.LEqual, cmode.DepthTest);
            Assert.Equal (true, cmode.DepthTestEnabled);
            Assert.Equal (true, cmode.DepthWriteEnabled);

        }

        [Fact]
        public void TestGetAlphaTest () {
            var cmode = new CompositingMode ();
            cmode.AlphaTest = CompositingMode.Greater;

            Assert.Equal (CompositingMode.Greater, cmode.AlphaTest);
        }

        [Fact]
        public void TestGetAlphaThreshold () {
            var cmode = new CompositingMode ();
            cmode.AlphaThreshold = 0.5f;

            Assert.Equal (0.5f, cmode.AlphaThreshold);
        }

        [Fact]
        public void TestSetBlender () {
            var cmode = new CompositingMode ();
            var blen = new Blender ();
            cmode.SetBlender (blen);

            Assert.Equal (blen, cmode.Blender);
        }

        [Fact]
        public void TestSetBlending () {
            var cmode = new CompositingMode ();
            cmode.Blending = CompositingMode.Modulate;

            Assert.Equal (CompositingMode.Modulate, cmode.Blending);
        }

        [Fact]
        public void TestSetColorWriteMask () {
            var cmode = new CompositingMode ();
            cmode.ColorWriteMask = 0xff00ff00u;

            Assert.Equal (0xff00ff00u, cmode.ColorWriteMask);
        }

        [Fact]
        public void TestSetDepthOffset () {
            var cmode = new CompositingMode ();
            cmode.SetDepthOffset (1.0f, 2.0f);

            Assert.Equal (1.0f, cmode.DepthOffsetFactor);
            Assert.Equal (2.0f, cmode.DepthOffsetUnits);
        }

        [Fact]
        public void TestSetDepthTest () {
            var cmode = new CompositingMode ();
            cmode.DepthTest = CompositingMode.Greater;

            Assert.Equal (CompositingMode.Greater, cmode.DepthTest);
        }

        [Fact]
        public void TestSetStencil () {
            var cmode = new CompositingMode ();
            var sten = new Stencil ();
            cmode.SetStencil (sten);

            Assert.Equal (sten, cmode.Stencil);
        }

        [Fact]
        public void TestSetDepthTestEnabled () {
            var cmode = new CompositingMode ();
            cmode.DepthTestEnabled = false;

            Assert.Equal (false, cmode.DepthTestEnabled);
        }

        [Fact]
        public void TestSetDepthWriteEnabled () {
            var cmode = new CompositingMode ();
            cmode.DepthWriteEnabled = false;

            Assert.Equal (false, cmode.DepthWriteEnabled);
        }

        [Fact]
        public void TestReferences () {
            var cmode = new CompositingMode ();
            var blen  = new Blender ();
            var stn   = new Stencil ();
            cmode.SetBlender (blen);
            cmode.SetStencil (stn);

            var refs = cmode.References;

            Assert.Equal (2, refs.Length);
            Assert.Equal (blen, cmode.Blender);
            Assert.Equal (stn, cmode.Stencil);
        }

        [Fact]
        public void TestDuplicate () {
            var cmode = new CompositingMode ();
            var blen  = new Blender ();
            var stn   = new Stencil ();
            cmode.AlphaTest = CompositingMode.Greater;
            cmode.AlphaThreshold = 0.5f;
            cmode.SetBlender (blen);
            cmode.SetStencil (stn);
            cmode.Blending = CompositingMode.Modulate;
            cmode.ColorWriteMask = 0xff00ff00u;
            cmode.DepthTest = CompositingMode.Greater;
            cmode.DepthTestEnabled = false;
            cmode.DepthWriteEnabled = false;
            cmode.SetDepthOffset (1.0f, 2.0f);
            cmode.UserID = 100;

            var dup = (CompositingMode)cmode.Duplicate ();

            Assert.Equal (cmode.Blender, dup.Blender);
            Assert.Equal (cmode.Blending, dup.Blending);
            Assert.Equal (cmode.AlphaThreshold, dup.AlphaThreshold);
            Assert.Equal (cmode.AlphaTest, dup.AlphaTest);
            Assert.Equal (cmode.DepthOffsetFactor, dup.DepthOffsetFactor);
            Assert.Equal (cmode.DepthOffsetUnits, dup.DepthOffsetUnits);
            Assert.Equal (cmode.DepthTestEnabled, dup.DepthTestEnabled);
            Assert.Equal (cmode.DepthTest, dup.DepthTest);
            Assert.Equal (cmode.DepthTestEnabled, dup.DepthTestEnabled);
            Assert.Equal (cmode.DepthWriteEnabled, dup.DepthWriteEnabled);
            Assert.Equal (cmode.UserID, dup.UserID);
        }
    }
}
